home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / vsuck / VReturn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-09  |  2.8 KB  |  117 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. /*
  7. **      $Id: VReturn.c,v 30.0 1994/06/10 18:09:35 dice Exp $
  8. **
  9. **      Convert a directory of examples into a directory of ventura
  10. **      @EXAMPLE lines.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #define unless(x)       if(!(x))
  17. #define MAX_NAME        256
  18.  
  19. #define unless(x)       if(!( x ))
  20.  
  21. char *SetSName(char *, char *);
  22. char *TailPath(char *path);
  23.  
  24. main(xac, xav)
  25. int xac;
  26. char *xav[];
  27. {
  28.     short i;
  29.     FILE *fi=0;
  30.     FILE *fo=0;
  31.     int ac;
  32.     char **av;
  33.  
  34.     expand_args(xac, xav, &ac, &av);
  35.  
  36.     if (ac < 2) {
  37.         puts("VReturn <pattern>");
  38.         puts("; Convert .c files to .v ventura @EXAMPLE_LIB entries");
  39.         exit(1);
  40.     }
  41.  
  42.     for (i = 1; i < ac; ++i) {
  43.         char *file = av[i];
  44.         short len = strlen(file);
  45.         short doth = 1;
  46.  
  47.         if (!( len >= 2 && (file[len-1] == 'c' || file[len-1] == 'C') && file[len-2] == '.'))
  48.                 {
  49.                 doth =0;
  50.                 printf("Error: name %s does not end with .c\n",file);
  51.                 }
  52.  
  53.         fi = fopen(file, "r");
  54.         if (fi && doth) {
  55.  
  56.             file[len-1]='v';
  57.             printf("Processing file %s\n",file);
  58.  
  59.             fo = fopen(file, "w");
  60.             if (!fo) {
  61.                 printf("Error: Unable to open %s for write\n", file);
  62.                 exit(1);
  63.             }
  64.  
  65.             scancfile(fi, fo, file);
  66.  
  67.             fclose(fo);
  68.             fclose(fi);
  69.             fo = fi = 0;
  70.         } else {
  71.             printf("Unable to read %s\n", file);
  72.         }
  73.     }
  74.     return(0);
  75. }
  76.  
  77. scancfile(FILE *in, FILE *out, char*name)
  78. {
  79. char    c;
  80.  
  81.         fprintf(out,"\r\n@EXAMPLE_LIB = ");
  82.  
  83.         while( EOF != (c=fgetc(in)) )
  84.                 {
  85.                 switch ( c ) {
  86.                         case 10:        // LineFeed
  87.                                 fprintf(out,"<R>\r\n");
  88.                                 break;
  89.                         case '<':
  90.                                 fprintf(out,"<<");
  91.                                 break;
  92.                         case '>':
  93.                                 fprintf(out,">>");
  94.                                 break;
  95.                         default:
  96.                                 unless( c==13 )        // We force CR, LF
  97.                                         fputc(c, out);
  98.             }
  99.                 }
  100.         fprintf(out,"\r\n");
  101.         fprintf(out,"\r\n");
  102. }
  103.  
  104.  
  105. /*
  106. **      Return filename portion of complete path
  107. */
  108. char *TailPath(char *path)
  109. {
  110. char *last;
  111.  
  112.     unless( last=strrchr(path,'/' ) )    // Return last slash...
  113.         unless( last=strrchr(path,':') ) // or if no slash, last :
  114.             return( path );             // or if neither, input string
  115.     return( last+1 );
  116. }
  117.